package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
//启用属性的批量注入
@EnableConfigurationProperties(MinioProperties.class)
@ConditionalOnProperty(name="minio.endpoint")
public class MinioConfiguration {

    @Autowired
    private MinioProperties minioProperties ;

    @Bean("minioClient")
    public MinioClient minioClient(){
        MinioClient client = MinioClient.builder()
                .endpoint(minioProperties.getEndpoint())
                .credentials(minioProperties.getAccessKey(), minioProperties.getSecretKey())
                .build();

        return client ;
    }

}
